package com.value.servlet;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.tool.toobean.MyTools;
import com.value.daos.admindaos;
import com.value.valuebean.admin;

public class adminlogin extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=gb2312");
		PrintWriter out = response.getWriter();
		admin admin1=new admin();
		String adminname = MyTools.toChinese(request.getParameter("name"));
		String adminpassword =MyTools.toChinese( request.getParameter("password"));
		
		
		admin1.setArootname(adminname);
		admin1.setArootpwd(adminpassword);
		
		admindaos ad = new admindaos();
		int rt = ad.checkadmin(admin1);
		
		if(rt==0){
			HttpSession session = request.getSession();
			session.setAttribute("username", admin1.getArootname());
			response.setContentType("text/html;charset=UTF-8");
			response.sendRedirect("admin/adminindex.jsp");
			}
			else if(rt==1){
				response.setContentType("text/html;charset=UTF-8");
				response.sendRedirect("admin/adminlogin.jsp?state=error");
			}
		out.close();
	}
	}


